<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Report extends CI_Controller {
 	public function __construct()
    {
        parent::__construct();
        session_start();
        //$this->output->enable_profiler(FALSE);
    	if (!isset($_SESSION['uid']) || $_SESSION['uid'] < 1){
	    	redirect('memberlogin/requiredmessage','refresh');
	    }
	    elseif ($_SESSION['role_id'] !=1){
    		redirect('memberlogin/restriction','refresh');
	    }
	    $data['menus'] = 'menus';
        $data['left'] = 'report/report_left';
        $data['content_left'] = "report";
		$this->load->vars($data);
    }
	    
	public function index()
	{
		/*$data['title'] = "Report - Friends-International Organization";
		$data['main'] = 'report/report';
		$this->load->vars($data);
		$this->load->view('template');*/
        redirect('report/staffinfo','refresh');  
	}
    
    public function staffinfo()
    {
        $data['title'] = "All staffs - Friends-International Organization";
		$data['main'] = 'report/staffinfo';
        $data['teams'] = $this->MTeam->getTeamDropdown();
		$data['profiles'] = $this->MStaff->getAllProfiles('');
		$this->load->vars($data);
		$this->load->view('template'); 
    }
    
    public function searchstaff()
    {
        if($this->input->post('TeamID') > 0){ 
            if($this->input->post('endprobation')){
                $data['title'] = "List of end probation staffs";
        		$data['main'] = 'report/staffendprobation';
                $data['teams'] = $this->MTeam->getTeamDropdown();
        		$data['profiles'] = $this->MStaff->getAllEndprobationStaffs($this->input->post('TeamID'));
            }
            elseif($this->input->post('report_name')){ 
                $data['title'] = "List all staffs haven't received training";
        		$data['main'] = 'report/staffinfo';
                $data['teams'] = $this->MTeam->getTeamDropdown();
        		$data['profiles'] = $this->MReport->getStaffsNotReceiveTraining($this->input->post('TeamID'));
                $data['report_name'] = "notreceived";
            }
            else{
                $data['title'] = "All staffs - Friends-International Organization";
            	$data['main'] = 'report/staffinfo';
                $data['teams'] = $this->MTeam->getTeamDropdown();
        		$data['profiles'] = $this->MStaff->getAllProfiles(null, $this->input->post('TeamID'));
            }
    		$this->load->vars($data);
    		$this->load->view('template');   
        }else {
            if($this->input->post('endprobation')){
                redirect('report/endprobation','refresh');
            } 
            elseif($this->input->post('report_name'))
            {
                redirect('report/staffnotreceivetraining','refresh');
            }
            else
            {
                redirect('report/staffinfo','refresh');   
            }
        }   
    }
    
    public function salaryIncrease()
    {
        $data['title'] = "All staffs with salary increase this month";
		$data['main'] = 'report/salaryincrease';
		$data['staffs'] = $this->MReport->getStaffBySalaryIncreaseThisMonth();
		$this->load->vars($data);
		$this->load->view('template');
    }
    
    public function endProbation()
    {
        $data['title'] = "List of end probation staffs";
		$data['main'] = 'report/staffendprobation';
        $data['teams'] = $this->MTeam->getTeamDropdown();
		$data['profiles'] = $this->MStaff->getAllEndprobationStaffs();
		$this->load->vars($data);
		$this->load->view('template');    
    }
    
    public function staffTraining()
    {
        $data['title'] = "Staff Training";
		$data['main'] = 'report/stafftraining';
        $type = null;
        if(isset($_POST['RTType']) && $_POST['RTType'] != ''){
            $type = $_POST['RTType'];
        }
		$data['training'] = $this->MReport->getStaffTrainiing($type);
		$this->load->vars($data);
		$this->load->view('template');  
    }
    
    public function staffDesirableTraining()
    {
        $data['title'] = "Staff Desirable Training";
		$data['main'] = 'report/staffdesirabletraining';
        $data['course'] = $this->MTraining->getCourseDropdown();
        $topic = null;
        if(isset($_POST['CourseID']) && $_POST['CourseID'] > 0){
            $topic = $_POST['CourseID'];
        }
		$data['training'] = $this->MReport->getStaffDesirableTrainiing($topic);
		$this->load->vars($data);
		$this->load->view('template');  
    }
    
    public function staffNotReceiveTraining()
    {
        $data['title'] = "List all staffs haven't received training";
		$data['main'] = 'report/staffinfo';
        $data['teams'] = $this->MTeam->getTeamDropdown();
		$data['profiles'] = $this->MReport->getStaffsNotReceiveTraining();
        $data['report_name'] = "notreceived";
		$this->load->vars($data);
		$this->load->view('template'); 
    }
}
